package com.qingdai.config;

import jakarta.servlet.http.HttpServletRequest;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Data
@Component
public class RequestConfig {
    List<String> accessUrl = new ArrayList<>();
    @Value("${server.servlet.context-path}")
    private String contextPath;

    public boolean check(HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        accessUrl.add("/login");
        accessUrl.add("/userLogin");
        accessUrl.add("/swagger-ui");
        accessUrl.add("/v3");
        accessUrl.add("/address/es");
        accessUrl.add("/user/");

        for (int i = 0; i < accessUrl.size(); i++) {
            if (requestURI.startsWith(contextPath + accessUrl.get(i))) {
                return true;
            }
        }

        if (requestURI.endsWith("/xyz")) {
            return true;
        }

        return false;
    }
}
